package com.leetcode.Stack;

import java.util.Stack;

public class Leetcode739 {

    public int[] dailyTemperatures(int[] T) {
        int[] result = new int[T.length];
        Stack<Integer> temperatures = new Stack<>();
        for (int i = 0; i < T.length - 1; i++) {
            temperatures.push(T[i]);
            for (int j = i + 1; j < T.length; j++) {
                int firstDay = T[i];
                if (T[j] <= firstDay) {
                    temperatures.push(T[j]);
                } else {
                    result[i] = temperatures.size();
                    while (!temperatures.isEmpty()) {
                        temperatures.pop();
                    }
                    break;
                }
            }
            while (!temperatures.isEmpty()) {
                temperatures.pop();
            }
        }
        return result;
    }

    public static void main(String[] args) {
        int[] T = {55,38,53,81,61,93,97,32,43,78};
        new Leetcode739().dailyTemperatures(T);
    }
}
